
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 08/29/2014 12:08:26
-- Generated from EDMX file: C:\WorldBankBBS\WorldBankBBS.Data\DataModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [WorldBankBBS];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_File_Fileboard]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[File] DROP CONSTRAINT [FK_File_Fileboard];
GO
IF OBJECT_ID(N'[dbo].[FK_File_User]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[File] DROP CONSTRAINT [FK_File_User];
GO
IF OBJECT_ID(N'[dbo].[FK_Fileboard_Sig]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[Fileboard] DROP CONSTRAINT [FK_Fileboard_Sig];
GO
IF OBJECT_ID(N'[dbo].[FK_Message_Thread]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[Message] DROP CONSTRAINT [FK_Message_Thread];
GO
IF OBJECT_ID(N'[dbo].[FK_Message_User_From]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[Message] DROP CONSTRAINT [FK_Message_User_From];
GO
IF OBJECT_ID(N'[dbo].[FK_Message_User_To]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[Message] DROP CONSTRAINT [FK_Message_User_To];
GO
IF OBJECT_ID(N'[dbo].[FK_MessageUser_Message]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[MessageUser] DROP CONSTRAINT [FK_MessageUser_Message];
GO
IF OBJECT_ID(N'[dbo].[FK_MessageUser_User]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[MessageUser] DROP CONSTRAINT [FK_MessageUser_User];
GO
IF OBJECT_ID(N'[dbo].[FK_NewsUser_News]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[NewsUser] DROP CONSTRAINT [FK_NewsUser_News];
GO
IF OBJECT_ID(N'[dbo].[FK_NewsUser_User]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[NewsUser] DROP CONSTRAINT [FK_NewsUser_User];
GO
IF OBJECT_ID(N'[dbo].[FK_Notification_User]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[Notification] DROP CONSTRAINT [FK_Notification_User];
GO
IF OBJECT_ID(N'[dbo].[FK_PrivateMail_User_From]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[PrivateMail] DROP CONSTRAINT [FK_PrivateMail_User_From];
GO
IF OBJECT_ID(N'[dbo].[FK_PrivateMail_User_To]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[PrivateMail] DROP CONSTRAINT [FK_PrivateMail_User_To];
GO
IF OBJECT_ID(N'[dbo].[FK_Session_User]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[Session] DROP CONSTRAINT [FK_Session_User];
GO
IF OBJECT_ID(N'[dbo].[FK_SigUser_Sig]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[SigUser] DROP CONSTRAINT [FK_SigUser_Sig];
GO
IF OBJECT_ID(N'[dbo].[FK_SigUser_User]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[SigUser] DROP CONSTRAINT [FK_SigUser_User];
GO
IF OBJECT_ID(N'[dbo].[FK_Subboard_Sig]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[Subboard] DROP CONSTRAINT [FK_Subboard_Sig];
GO
IF OBJECT_ID(N'[dbo].[FK_Thread_Subboard]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[Thread] DROP CONSTRAINT [FK_Thread_Subboard];
GO
IF OBJECT_ID(N'[dbo].[FK_UserPreferences_User]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[UserPreference] DROP CONSTRAINT [FK_UserPreferences_User];
GO
IF OBJECT_ID(N'[dbo].[FK_UserSecurity_User]', 'F') IS NOT NULL
	ALTER TABLE [dbo].[UserSecurity] DROP CONSTRAINT [FK_UserSecurity_User];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[File]', 'U') IS NOT NULL
	DROP TABLE [dbo].[File];
GO
IF OBJECT_ID(N'[dbo].[Fileboard]', 'U') IS NOT NULL
	DROP TABLE [dbo].[Fileboard];
GO
IF OBJECT_ID(N'[dbo].[Log]', 'U') IS NOT NULL
	DROP TABLE [dbo].[Log];
GO
IF OBJECT_ID(N'[dbo].[Message]', 'U') IS NOT NULL
	DROP TABLE [dbo].[Message];
GO
IF OBJECT_ID(N'[dbo].[MessageUser]', 'U') IS NOT NULL
	DROP TABLE [dbo].[MessageUser];
GO
IF OBJECT_ID(N'[dbo].[News]', 'U') IS NOT NULL
	DROP TABLE [dbo].[News];
GO
IF OBJECT_ID(N'[dbo].[NewsUser]', 'U') IS NOT NULL
	DROP TABLE [dbo].[NewsUser];
GO
IF OBJECT_ID(N'[dbo].[Notification]', 'U') IS NOT NULL
	DROP TABLE [dbo].[Notification];
GO
IF OBJECT_ID(N'[dbo].[PrivateMail]', 'U') IS NOT NULL
	DROP TABLE [dbo].[PrivateMail];
GO
IF OBJECT_ID(N'[dbo].[Session]', 'U') IS NOT NULL
	DROP TABLE [dbo].[Session];
GO
IF OBJECT_ID(N'[dbo].[Sig]', 'U') IS NOT NULL
	DROP TABLE [dbo].[Sig];
GO
IF OBJECT_ID(N'[dbo].[SigUser]', 'U') IS NOT NULL
	DROP TABLE [dbo].[SigUser];
GO
IF OBJECT_ID(N'[dbo].[Subboard]', 'U') IS NOT NULL
	DROP TABLE [dbo].[Subboard];
GO
IF OBJECT_ID(N'[dbo].[Thread]', 'U') IS NOT NULL
	DROP TABLE [dbo].[Thread];
GO
IF OBJECT_ID(N'[dbo].[User]', 'U') IS NOT NULL
	DROP TABLE [dbo].[User];
GO
IF OBJECT_ID(N'[dbo].[UserPreference]', 'U') IS NOT NULL
	DROP TABLE [dbo].[UserPreference];
GO
IF OBJECT_ID(N'[dbo].[UserSecurity]', 'U') IS NOT NULL
	DROP TABLE [dbo].[UserSecurity];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Files'
CREATE TABLE [dbo].[File] (
	[FileUID] uniqueidentifier  NOT NULL,
	[FileboardUID] uniqueidentifier  NOT NULL,
	[Filename] nvarchar(512)  NOT NULL,
	[Description] nvarchar(max)  NULL,
	[UploadedByUserUID] uniqueidentifier  NULL,
	[Timestamp] datetime  NOT NULL,
	[IsDeleted] bit  NOT NULL
);
GO

-- Creating table 'Fileboards'
CREATE TABLE [dbo].[Fileboard] (
	[FileboardUID] uniqueidentifier  NOT NULL,
	[FileboardName] nvarchar(256)  NOT NULL,
	[FileboardDescription] nvarchar(max)  NULL,
	[SigUID] uniqueidentifier  NOT NULL,
	[IsDeleted] bit  NOT NULL,
	[DisplayOrder] int NOT NULL
);
GO

-- Creating table 'Logs'
CREATE TABLE [dbo].[Log] (
	[LogUID] uniqueidentifier  NOT NULL,
	[Message] nvarchar(max)  NOT NULL,
	[Extended] nvarchar(max)  NULL,
	[Timestamp] datetime  NOT NULL,
	[Type] nvarchar(50)  NULL,
	[SessionUID] uniqueidentifier  NULL
);
GO

-- Creating table 'Messages'
CREATE TABLE [dbo].[Message] (
	[MessageUID] uniqueidentifier  NOT NULL,
	[ThreadUID] uniqueidentifier  NOT NULL,
	[FromUserUID] uniqueidentifier  NOT NULL,
	[ToUserUID] uniqueidentifier  NULL,
	[Subject] nvarchar(256)  NOT NULL,
	[MessageBody] nvarchar(max)  NOT NULL,
	[Timestamp] datetime  NOT NULL,
	[IsDeleted] bit  NOT NULL
);
GO

-- Creating table 'MessageUsers'
CREATE TABLE [dbo].[MessageUser] (
	[MessageUID] uniqueidentifier  NOT NULL,
	[UserUID] uniqueidentifier  NOT NULL,
	[IsRead] bit  NOT NULL,
	[IsHidden] bit  NOT NULL,
	[ReadOn] datetime  NULL
);
GO

-- Creating table 'Notifications'
CREATE TABLE [dbo].[Notification] (
	[NotificationUID] uniqueidentifier  NOT NULL,
	[UserUID] uniqueidentifier  NOT NULL,
	[NotificationText] nvarchar(80)  NOT NULL,
	[NotificationPath] nvarchar(512)  NOT NULL,
	[NotificationSeen] bit  NOT NULL,
	[NotificationCleared] bit  NOT NULL,
	[NotificationFollowed] bit  NOT NULL,
	[Timestamp] datetime  NOT NULL
);
GO

-- Creating table 'PrivateMails'
CREATE TABLE [dbo].[PrivateMail] (
	[PrivateMailUID] uniqueidentifier  NOT NULL,
	[FromUserUID] uniqueidentifier  NOT NULL,
	[ToUserUID] uniqueidentifier  NOT NULL,
	[Subject] nvarchar(256)  NOT NULL,
	[Body] nvarchar(max)  NOT NULL,
	[Timestamp] datetime  NOT NULL,
	[IsRead] bit  NOT NULL,
	[IsDeleted] bit  NOT NULL,
	[HasReplied] bit  NOT NULL
);
GO

-- Creating table 'Sessions'
CREATE TABLE [dbo].[Session] (
	[SessionUID] uniqueidentifier  NOT NULL,
	[StartedOn] datetime  NOT NULL,
	[EndedOn] datetime  NULL,
	[UserUID] uniqueidentifier  NULL,
	[RemoteIP] nvarchar(50)  NULL,
	[Encoding] nchar(10)  NOT NULL
);
GO

-- Creating table 'Sigs'
CREATE TABLE [dbo].[Sig] (
	[SigUID] uniqueidentifier  NOT NULL,
	[SigName] nvarchar(50)  NOT NULL,
	[SigDescription] nvarchar(max)  NULL,
	[IsDeleted] bit  NOT NULL,
	[DisplayOrder] int NOT NULL,
);
GO

-- Creating table 'SigUsers'
CREATE TABLE [dbo].[SigUser] (
	[SigUID] uniqueidentifier  NOT NULL,
	[UserUID] uniqueidentifier  NOT NULL,
	[IsDeleted] bit  NOT NULL,
	[IsSigOp] bit  NOT NULL,
	[CanRead] bit  NOT NULL,
	[CanWrite] bit  NOT NULL
);
GO

-- Creating table 'Subboards'
CREATE TABLE [dbo].[Subboard] (
	[SubboardUID] uniqueidentifier  NOT NULL,
	[SubboardName] nvarchar(256)  NOT NULL,
	[SubboardDescription] nvarchar(max)  NULL,
	[SigUID] uniqueidentifier  NOT NULL,
	[IsDeleted] bit  NOT NULL,
	[DisplayOrder] int NOT NULL,
);
GO

-- Creating table 'Threads'
CREATE TABLE [dbo].[Thread] (
	[ThreadUID] uniqueidentifier  NOT NULL,
	[ThreadName] nvarchar(256)  NOT NULL,
	[ThreadDescription] nvarchar(max)  NULL,
	[SubboardUID] uniqueidentifier  NOT NULL,
	[IsDeleted] bit  NOT NULL
);
GO

-- Creating table 'Users'
CREATE TABLE [dbo].[User] (
	[UserUID] uniqueidentifier  NOT NULL,
	[UserName] nvarchar(50)  NOT NULL,
	[EMailAddress] nvarchar(512)  NOT NULL,
	[Password] binary(16)  NOT NULL,
	[Alias] nvarchar(256)  NULL,
	[RealName] nvarchar(256)  NULL,
	[IsDeleted] bit  NOT NULL,
	[IsValidated] bit  NOT NULL,
	[Website] nvarchar(2048)  NULL
);
GO

-- Creating table 'UserPreferences'
CREATE TABLE [dbo].[UserPreference] (
	[UserUID] uniqueidentifier  NOT NULL,
	[ScreenWidth] int  NOT NULL,
	[ScreenHeight] int  NOT NULL,
	[HelpLevel] int  NOT NULL
);
GO

-- Creating table 'News'
CREATE TABLE [dbo].[News] (
	[NewsUID] uniqueidentifier  NOT NULL,
	[NewsSubject] nvarchar(512)  NOT NULL,
	[NewsMessage] nvarchar(max)  NOT NULL,
	[Timestamp] datetime  NOT NULL,
	[IsDeleted] bit  NOT NULL,
	[Author] uniqueidentifier  NOT NULL
);
GO

-- Creating table 'NewsUsers'
CREATE TABLE [dbo].[NewsUser] (
	[NewsUID] uniqueidentifier  NOT NULL,
	[UserUID] uniqueidentifier  NOT NULL,
	[DateRead] datetime  NOT NULL
);
GO

-- Creating table 'UserSecurities'
CREATE TABLE [dbo].[UserSecurity] (
	[UserUID] uniqueidentifier  NOT NULL,
	[IsNewsAdmin] bit  NOT NULL,
	[IsSigAdmin] bit  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [FileUID] in table 'Files'
ALTER TABLE [dbo].[File]
ADD CONSTRAINT [PK_Files]
	PRIMARY KEY CLUSTERED ([FileUID] ASC);
GO

-- Creating primary key on [FileboardUID] in table 'Fileboards'
ALTER TABLE [dbo].[Fileboard]
ADD CONSTRAINT [PK_Fileboards]
	PRIMARY KEY CLUSTERED ([FileboardUID] ASC);
GO

-- Creating primary key on [LogUID] in table 'Logs'
ALTER TABLE [dbo].[Log]
ADD CONSTRAINT [PK_Logs]
	PRIMARY KEY CLUSTERED ([LogUID] ASC);
GO

-- Creating primary key on [MessageUID] in table 'Messages'
ALTER TABLE [dbo].[Message]
ADD CONSTRAINT [PK_Messages]
	PRIMARY KEY CLUSTERED ([MessageUID] ASC);
GO

-- Creating primary key on [MessageUID], [UserUID] in table 'MessageUsers'
ALTER TABLE [dbo].[MessageUser]
ADD CONSTRAINT [PK_MessageUsers]
	PRIMARY KEY CLUSTERED ([MessageUID], [UserUID] ASC);
GO

-- Creating primary key on [NotificationUID] in table 'Notifications'
ALTER TABLE [dbo].[Notification]
ADD CONSTRAINT [PK_Notifications]
	PRIMARY KEY CLUSTERED ([NotificationUID] ASC);
GO

-- Creating primary key on [PrivateMailUID] in table 'PrivateMails'
ALTER TABLE [dbo].[PrivateMail]
ADD CONSTRAINT [PK_PrivateMails]
	PRIMARY KEY CLUSTERED ([PrivateMailUID] ASC);
GO

-- Creating primary key on [SessionUID] in table 'Sessions'
ALTER TABLE [dbo].[Session]
ADD CONSTRAINT [PK_Sessions]
	PRIMARY KEY CLUSTERED ([SessionUID] ASC);
GO

-- Creating primary key on [SigUID] in table 'Sigs'
ALTER TABLE [dbo].[Sig]
ADD CONSTRAINT [PK_Sigs]
	PRIMARY KEY CLUSTERED ([SigUID] ASC);
GO

-- Creating primary key on [SigUID], [UserUID] in table 'SigUsers'
ALTER TABLE [dbo].[SigUser]
ADD CONSTRAINT [PK_SigUsers]
	PRIMARY KEY CLUSTERED ([SigUID], [UserUID] ASC);
GO

-- Creating primary key on [SubboardUID] in table 'Subboards'
ALTER TABLE [dbo].[Subboard]
ADD CONSTRAINT [PK_Subboards]
	PRIMARY KEY CLUSTERED ([SubboardUID] ASC);
GO

-- Creating primary key on [ThreadUID] in table 'Threads'
ALTER TABLE [dbo].[Thread]
ADD CONSTRAINT [PK_Threads]
	PRIMARY KEY CLUSTERED ([ThreadUID] ASC);
GO

-- Creating primary key on [UserUID] in table 'Users'
ALTER TABLE [dbo].[User]
ADD CONSTRAINT [PK_Users]
	PRIMARY KEY CLUSTERED ([UserUID] ASC);
GO

-- Creating primary key on [UserUID] in table 'UserPreferences'
ALTER TABLE [dbo].[UserPreference]
ADD CONSTRAINT [PK_UserPreferences]
	PRIMARY KEY CLUSTERED ([UserUID] ASC);
GO

-- Creating primary key on [NewsUID] in table 'News'
ALTER TABLE [dbo].[News]
ADD CONSTRAINT [PK_News]
	PRIMARY KEY CLUSTERED ([NewsUID] ASC);
GO

-- Creating primary key on [NewsUID], [UserUID] in table 'NewsUsers'
ALTER TABLE [dbo].[NewsUser]
ADD CONSTRAINT [PK_NewsUsers]
	PRIMARY KEY CLUSTERED ([NewsUID], [UserUID] ASC);
GO

-- Creating primary key on [UserUID] in table 'UserSecurities'
ALTER TABLE [dbo].[UserSecurity]
ADD CONSTRAINT [PK_UserSecurity]
	PRIMARY KEY CLUSTERED ([UserUID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [FileboardUID] in table 'Files'
ALTER TABLE [dbo].[File]
ADD CONSTRAINT [FK_File_Fileboard]
	FOREIGN KEY ([FileboardUID])
	REFERENCES [dbo].[Fileboard]
		([FileboardUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_File_Fileboard'
CREATE INDEX [IX_FK_File_Fileboard]
ON [dbo].[File]
	([FileboardUID]);
GO

-- Creating foreign key on [UploadedByUserUID] in table 'Files'
ALTER TABLE [dbo].[File]
ADD CONSTRAINT [FK_File_User]
	FOREIGN KEY ([UploadedByUserUID])
	REFERENCES [dbo].[User]
		([UserUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_File_User'
CREATE INDEX [IX_FK_File_User]
ON [dbo].[File]
	([UploadedByUserUID]);
GO

-- Creating foreign key on [SigUID] in table 'Fileboards'
ALTER TABLE [dbo].[Fileboard]
ADD CONSTRAINT [FK_Fileboard_Sig]
	FOREIGN KEY ([SigUID])
	REFERENCES [dbo].[Sig]
		([SigUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Fileboard_Sig'
CREATE INDEX [IX_FK_Fileboard_Sig]
ON [dbo].[Fileboard]
	([SigUID]);
GO

-- Creating foreign key on [ThreadUID] in table 'Messages'
ALTER TABLE [dbo].[Message]
ADD CONSTRAINT [FK_Message_Thread]
	FOREIGN KEY ([ThreadUID])
	REFERENCES [dbo].[Thread]
		([ThreadUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Message_Thread'
CREATE INDEX [IX_FK_Message_Thread]
ON [dbo].[Message]
	([ThreadUID]);
GO

-- Creating foreign key on [FromUserUID] in table 'Messages'
ALTER TABLE [dbo].[Message]
ADD CONSTRAINT [FK_Message_User_From]
	FOREIGN KEY ([FromUserUID])
	REFERENCES [dbo].[User]
		([UserUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Message_User_From'
CREATE INDEX [IX_FK_Message_User_From]
ON [dbo].[Message]
	([FromUserUID]);
GO

-- Creating foreign key on [ToUserUID] in table 'Messages'
ALTER TABLE [dbo].[Message]
ADD CONSTRAINT [FK_Message_User_To]
	FOREIGN KEY ([ToUserUID])
	REFERENCES [dbo].[User]
		([UserUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Message_User_To'
CREATE INDEX [IX_FK_Message_User_To]
ON [dbo].[Message]
	([ToUserUID]);
GO

-- Creating foreign key on [MessageUID] in table 'MessageUsers'
ALTER TABLE [dbo].[MessageUser]
ADD CONSTRAINT [FK_MessageUser_Message]
	FOREIGN KEY ([MessageUID])
	REFERENCES [dbo].[Message]
		([MessageUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [UserUID] in table 'MessageUsers'
ALTER TABLE [dbo].[MessageUser]
ADD CONSTRAINT [FK_MessageUser_User]
	FOREIGN KEY ([UserUID])
	REFERENCES [dbo].[User]
		([UserUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MessageUser_User'
CREATE INDEX [IX_FK_MessageUser_User]
ON [dbo].[MessageUser]
	([UserUID]);
GO

-- Creating foreign key on [UserUID] in table 'Notifications'
ALTER TABLE [dbo].[Notification]
ADD CONSTRAINT [FK_Notification_User]
	FOREIGN KEY ([UserUID])
	REFERENCES [dbo].[User]
		([UserUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Notification_User'
CREATE INDEX [IX_FK_Notification_User]
ON [dbo].[Notification]
	([UserUID]);
GO

-- Creating foreign key on [FromUserUID] in table 'PrivateMails'
ALTER TABLE [dbo].[PrivateMail]
ADD CONSTRAINT [FK_PrivateMail_User_From]
	FOREIGN KEY ([FromUserUID])
	REFERENCES [dbo].[User]
		([UserUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PrivateMail_User_From'
CREATE INDEX [IX_FK_PrivateMail_User_From]
ON [dbo].[PrivateMail]
	([FromUserUID]);
GO

-- Creating foreign key on [ToUserUID] in table 'PrivateMails'
ALTER TABLE [dbo].[PrivateMail]
ADD CONSTRAINT [FK_PrivateMail_User_To]
	FOREIGN KEY ([ToUserUID])
	REFERENCES [dbo].[User]
		([UserUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PrivateMail_User_To'
CREATE INDEX [IX_FK_PrivateMail_User_To]
ON [dbo].[PrivateMail]
	([ToUserUID]);
GO

-- Creating foreign key on [UserUID] in table 'Sessions'
ALTER TABLE [dbo].[Session]
ADD CONSTRAINT [FK_Session_User]
	FOREIGN KEY ([UserUID])
	REFERENCES [dbo].[User]
		([UserUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Session_User'
CREATE INDEX [IX_FK_Session_User]
ON [dbo].[Session]
	([UserUID]);
GO

-- Creating foreign key on [SigUID] in table 'SigUsers'
ALTER TABLE [dbo].[SigUser]
ADD CONSTRAINT [FK_SigUser_Sig]
	FOREIGN KEY ([SigUID])
	REFERENCES [dbo].[Sig]
		([SigUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [SigUID] in table 'Subboards'
ALTER TABLE [dbo].[Subboard]
ADD CONSTRAINT [FK_Subboard_Sig]
	FOREIGN KEY ([SigUID])
	REFERENCES [dbo].[Sig]
		([SigUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Subboard_Sig'
CREATE INDEX [IX_FK_Subboard_Sig]
ON [dbo].[Subboard]
	([SigUID]);
GO

-- Creating foreign key on [UserUID] in table 'SigUsers'
ALTER TABLE [dbo].[SigUser]
ADD CONSTRAINT [FK_SigUser_User]
	FOREIGN KEY ([UserUID])
	REFERENCES [dbo].[User]
		([UserUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SigUser_User'
CREATE INDEX [IX_FK_SigUser_User]
ON [dbo].[SigUser]
	([UserUID]);
GO

-- Creating foreign key on [SubboardUID] in table 'Threads'
ALTER TABLE [dbo].[Thread]
ADD CONSTRAINT [FK_Thread_Subboard]
	FOREIGN KEY ([SubboardUID])
	REFERENCES [dbo].[Subboard]
		([SubboardUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Thread_Subboard'
CREATE INDEX [IX_FK_Thread_Subboard]
ON [dbo].[Thread]
	([SubboardUID]);
GO

-- Creating foreign key on [UserUID] in table 'UserPreferences'
ALTER TABLE [dbo].[UserPreference]
ADD CONSTRAINT [FK_UserPreferences_User]
	FOREIGN KEY ([UserUID])
	REFERENCES [dbo].[User]
		([UserUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [NewsUID] in table 'NewsUsers'
ALTER TABLE [dbo].[NewsUser]
ADD CONSTRAINT [FK_NewsUser_News]
	FOREIGN KEY ([NewsUID])
	REFERENCES [dbo].[News]
		([NewsUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [UserUID] in table 'NewsUsers'
ALTER TABLE [dbo].[NewsUser]
ADD CONSTRAINT [FK_NewsUser_User]
	FOREIGN KEY ([UserUID])
	REFERENCES [dbo].[User]
		([UserUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_NewsUser_User'
CREATE INDEX [IX_FK_NewsUser_User]
ON [dbo].[NewsUser]
	([UserUID]);
GO

-- Creating foreign key on [UserUID] in table 'UserSecurities'
ALTER TABLE [dbo].[UserSecurity]
ADD CONSTRAINT [FK_UserSecurity_User]
	FOREIGN KEY ([UserUID])
	REFERENCES [dbo].[User]
		([UserUID])
	ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------

/* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.Sig ADD CONSTRAINT
	DF_Sig_SigUID DEFAULT newid() FOR SigUID
GO
ALTER TABLE dbo.Sig SET (LOCK_ESCALATION = TABLE)
GO
COMMIT

/* To prevent any potential data loss issues, you should review this script in detail before running it outside the context of the database designer.*/
BEGIN TRANSACTION
SET QUOTED_IDENTIFIER ON
SET ARITHABORT ON
SET NUMERIC_ROUNDABORT OFF
SET CONCAT_NULL_YIELDS_NULL ON
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
COMMIT
BEGIN TRANSACTION
GO
ALTER TABLE dbo.Subboard ADD CONSTRAINT
	DF_Subboard_SubboardUID DEFAULT newid() FOR SubboardUID
GO
ALTER TABLE dbo.Subboard SET (LOCK_ESCALATION = TABLE)
GO
COMMIT

